<template>
    <el-form :model="modelValue" :rules="rules" ref="formRef" label-width="auto">
        <el-form-item label="签约人" v-if="currentAccountData.memberType==2">
            <el-radio-group v-model="signingPerson">
                <el-radio :value="0" label="法人"></el-radio>
                <el-radio :value="1" label="经办人"></el-radio>
            </el-radio-group>
        </el-form-item>
        <el-form-item label="手机号" v-if="!isMobile()">
            <div class="readonly">
                {{ currentAccountData.mobileNumber }}
            </div>
        </el-form-item>
        <el-form-item label="经办人手机号" prop="operatorMobile" v-else>
            <el-input v-model="modelValue.operatorMobile" placeholder="请输入"></el-input>
        </el-form-item>
        <template v-if="currentAccountData.memberType != 1 && signingPerson">
            <el-form-item label="经办人姓名" prop="operatorName">
                <el-input v-model="modelValue.operatorName" placeholder="请输入"/>
            </el-form-item>
            <el-form-item label="经办人身份证号" prop="operatorIdCardNo">
                <el-input v-model="modelValue.operatorIdCardNo" placeholder="请输入"/>
            </el-form-item>
        </template>
        <el-form-item label="验证码" prop="code">
            <div class="space">
                <el-input placeholder="请输入" v-model="modelValue.code" />
                <el-button type="primary" v-if="!sendCodeStatus.status"
                    :disabled="!regPhone(modelValue.operatorMobile || '15683956578')" @click="send">获取验证码</el-button>
                <el-button v-else>重新获取({{ sendCodeStatus.time }}s)</el-button>
            </div>
        </el-form-item>
    </el-form>
</template>

<script setup>
import { ref } from "vue";
import { regPhone } from "@/utils/validate";
import { code, mobile, identityCard, required,length } from "../../../rules";
const props = defineProps({
    modelValue: {
        type: Object,
        required: true
    },
    sendCodeStatus: {
        type: Object,
        required: true
    },
    currentAccountData: {
        type: Object,
        required: true
    },
})
const isMobile = () => {
    if ([1, 3].includes(props.currentAccountData.memberType)) {
        return true;
    } else {
        console.log(!!signingPerson.value)
        return !!signingPerson.value;
    }
}
const emit = defineEmits(['sendCode']);
const signingPerson = ref(0);
const rules = {
    code: [code(6), required('验证码不能为空')],
    operatorMobile: [required('手机号不能为空'), mobile],
    operatorIdCardNo: [required('身份证号不能为空'), identityCard],
    operatorName:[
        required('姓名不能为空'),
        length(2, 20, '姓名')
    ]
}
const send = () => {
    emit('sendCode')
}
const formRef = ref()
const validate = () => {
    return new Promise((resolve) => {
        formRef.value.validate(valid => {
            resolve(valid)
        })
    })
}
const resetFields = () => {
    return formRef.value.resetFields()
}
defineExpose({
    validate,
    resetFields
})
</script>

<style lang="scss" scoped></style>